package com.cloud.demo.test;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.file.FileReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class test2 {

    public static void main(String[] args) {
        File f1=new File("C:/cisco/nbr/Trouble shooting with confId.txt");
        File f2=new File("C:/cisco/nbr/Trouble shooting with trackingId.txt");
        File f3=new File("C:/cisco/nbr/NBR Analysis Dashboard.txt");
        File f4=new File("C:/cisco/nbr/Recording API Monitoring Dashboard.txt");
        File f5=new File("C:/cisco/nbr/Recording Monitoring Dashboard.txt");
        File f6=new File("C:/cisco/nbr/Trouble shooting with Email.txt");
        File f7=new File("C:/cisco/nbr/Trouble shooting with site---Not support China and Fedramp.txt");
        File f8=new File("C:/cisco/nbr/AIBridge Trouble Shooting By ConfId and VoiceMeetingId.txt");
        File f9=new File("C:/cisco/nbr/NBR Business View Usage -- Including For S3.txt");
        File f10=new File("C:/cisco/nbr/NBR Business View Usage -- Capacity Model.txt");
        File f11=new File("C:/cisco/nbr/NBR Business View Usage -- PMMonthly Metrics requirement - New by Telemetry Log.txt");
        File f12=new File("C:/cisco/nbr/NBR Download & Upload Statistics Dashboard (S3 + NFS).txt");
        File f13=new File("C:/cisco/nbr/NBR PlaybackDownload Metrics.txt");
        File f14=new File("C:/cisco/nbr/NBR Recording Delay Time.txt");
        File f15=new File("C:/cisco/nbr/NBR SLISLO.txt");
        File f16=new File("C:/cisco/nbr/NBR Transcript Dashboard.txt");
        File f17=new File("C:/cisco/nbr/Recording Service Portal.txt");
        File f18=new File("C:/cisco/nbr/UCF Player Dashboard.txt");

        List<File> fileList=new ArrayList<>();
        fileList.add(f1);
        fileList.add(f2);
        fileList.add(f3);
        fileList.add(f4);
        fileList.add(f5);
        fileList.add(f6);
        fileList.add(f7);
        fileList.add(f8);
        fileList.add(f9);
        fileList.add(f10);
        fileList.add(f11);
        fileList.add(f12);
        fileList.add(f13);
        fileList.add(f14);
        fileList.add(f15);
        fileList.add(f16);
        fileList.add(f17);
        fileList.add(f18);

        Set<DS> list=new HashSet<>();
        fileList.forEach(file->{
            FileReader fileReader=FileReader.create(file);
            String json=fileReader.readString();
            String regex = "\"datasource\":\\s*\\{\\s*\"type\":\\s*\"([^\"]+)\",\\s*\"uid\":\\s*\"([^\"]+)\"\\s*\\}";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(json);
            while (matcher.find()) {
                list.add(new DS(matcher.group(1),matcher.group(2)));
            }
        });
        System.out.println(list.size());
        System.out.println(list);
        ExcelWriter writer = ExcelUtil.getWriter("C:/cisco/nbr.xlsx");
        writer.write(list, true);
        // 关闭writer，释放内存
        writer.close();
    }
}
